<!DOCTYPE html>
<html>
<head th:include="include :: header"></head>
<script type="text/javascript">
    if (window.top !== window.self) {
        window.top.location = window.location;
    }
</script>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display:none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>软考题库管理</h2>
            <p>Soft Exam Question Bank</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input" autocomplete="off" value="admin">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input" autocomplete="off" value="888888">
            </div>
            <div class="layui-form-item" th:if="${kaptchaOpen}">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>
                        <input type="text" name="kaptcha" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input" autocomplete="off">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img th:src="@{/kaptcha}" class="layadmin-user-login-codeimg" id="kaptcha">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login-submit" id="submit">登 入</button>
            </div>
        </div>
    </div>
    <div class="layui-trans layadmin-user-login-footer">
        <p>© 2019 <a>llsydn.com</a></p>
        <p>
            <span><a href="https://blog.csdn.net/qq_24101357" target="_blank">CSDN</a></span>
            <span><a href="https://github.com/llsydn" target="_blank">GitHub</a></span>
            <span><a href="https://my.oschina.net/llsydn" target="_blank">开源中国</a></span>
        </p>
    </div>
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">
    layui.config({
        base: ctx + '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form'], function () {
        var $ = layui.$, form = layui.form;

        form.render();

        //提交
        form.on('submit(login-submit)', function (obj) {
            //请求登入接口
            commonJs.openAjax(ctx + "/login", obj, function (result) {
                if (result.code == 0) {
                    commonJs.openMsg('success', '登入成功', function () {
                        location.href = ctx + '/index'; //后台主页
                    });
                } else {
                    commonJs.openMsg('error', result.msg, function () {
                        getKaptcha();
                    });
                }
            });
        });

        $('#kaptcha').click(function () {
            getKaptcha();
        });

        //回车登录快捷键
        $('body').keydown(function (e) {
            // 兼容FF和IE和Opera
            var event = e || window.event;
            var keyCode = event.keyCode || event.which;
            if (keyCode === 13) {
                $('#submit').click();
            }
        });

        function getKaptcha() {
            $("#kaptcha").attr("src", ctx + "/kaptcha?" + Math.floor(Math.random() * 100));
        }
    });
</script>
</body>
</html>